package info.guerrero.cartaalta;

import java.util.ArrayList;

import info.guerrero.cartaalta.SelectActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class SelectActivity extends Activity {
	private TextView textView;
	private Spinner mySpinner;
	private ArrayAdapter<Integer> adapter;
	public int myPosition;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_select);
        mySpinner = (Spinner) this.findViewById(R.id.spinnerNumJug);

        adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item );
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
      
       for(int i=0;i<=11;i++){
    	   adapter.add(i+1);
       }
       
       mySpinner.setAdapter(adapter);
       mySpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    	   public void onItemSelected(AdapterView<?> parentView, View selectedItemView,
    			   					  int position, long id){
    		   Toast.makeText(parentView.getContext(), "Has seleccionado " + parentView.getItemAtPosition(position).toString(), Toast.LENGTH_LONG);
    		myPosition=position;
    	Publico.numberOfPlayers=position;
    	   }
    	   public void onNothingSelected(AdapterView<?> parentView){
    		   
    	   }

   		
       });
      
       Log.i("AAA","spinner0");
       
	}
	public int getPeople(){
		if(myPosition==0){
			return 0;
		}
		
		return myPosition;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.select, menu);
		return true;
	}
	public void aceptPlayers(View v){
    	Log.d("info.guerrero.highcard","Opening Main activity");
    	Intent intent = new Intent(this,PlayersActivity.class);
    	intent.putExtra("NumberPlayer", myPosition);
    	
    	startActivity(intent);
    		
	}

}
